package com.woniuxy.personal.core.controller;


import com.woniuxy.common.CommonResult;


import com.woniuxy.personal.client.dto.CarMycar;
import com.woniuxy.personal.core.model.PlUser;
import com.woniuxy.personal.core.service.PlUserService;
import com.woniuxy.personal.core.vo.UserVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
public class PlUserController {


    @Resource
    PlUserService plUserService;


    /**
     * Description : 根据username找对象  <br/>
     * ChangeLog : 1. 创建 (2021/7/1 10:39 [binhu]);
     * @param username
     * @return com.woniuxy.common.CommonResult<com.woniuxy.personal.core.model.PlUser>
    */
    @GetMapping("/selectUser/{username}")
    public CommonResult<PlUser> selectUser(@PathVariable("username") String username){
        PlUser plUser = plUserService.selectUser(username);
        return  CommonResult.success(plUser);
    }

    /**
     * Description : 我的积分  <br/>
     * ChangeLog : 1. 创建 (2021/7/1 10:40 [binhu]);
     * @param username
     * @return com.woniuxy.common.CommonResult
    */
    @ApiOperation(value = "我的积分")
    @GetMapping("/selectScore")
    public CommonResult selectScore(String username){
        Integer score = plUserService.selectScore(username);
        return CommonResult.success(score);
    }
    /**
     * Description : 爱车估价
     * ChangeLog : 1. 创建 (2021/6/30 17:51 [fulang]);
     * @param userId
     * @return java.lang.String
    */
    @ApiOperation(value = "爱车估价")
    @GetMapping("/appraisal")
    public BigDecimal appraisal(Integer userId,Integer carId){
        BigDecimal  price = plUserService.appraisal(userId,carId);
        return price;
    }
    /**
     * Description : 选择我的车辆
     * ChangeLog : 1. 创建 (2021/7/2 15:05 [fulang]);
     * @param userId
     * @return com.woniuxy.common.CommonResult<java.util.List<com.woniuxy.personal.client.dto.CarMycar>>
    */
    @ApiOperation(value = "选择我的车辆")
    @GetMapping("/selectMyCar")
    public CommonResult<List<CarMycar>> selectMyCar(Integer userId){
        List<CarMycar> carMycars = plUserService.selectMycar(userId);
        return CommonResult.success(carMycars);
    }


    @PostMapping("insertUser")
    public CommonResult insertUser(@RequestBody UserVo userVo){
        int i = this.plUserService.insertUser(userVo);
        if (i > 0){
            return CommonResult.success();
        }
        return CommonResult.fail();
    }
}

